<?php

namespace app\admin\model;

use think\Model;


class AdLog extends Model
{

    

    

    // 表名
    protected $name = 'ad_log';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'come_text',
        'adtype_text',
        'node_text',
        'trigger_text',
        'status_text',
        'play_text'
    ];
    

    
    public function getComeList()
    {
        return ['0' => __('Come 0'), '1' => __('Come 1')];
    }

    public function getAdtypeList()
    {
        return ['0' => __('Adtype 0'), '1' => __('Adtype 1'), '2' => __('Adtype 2'), '3' => __('Adtype 3')];
    }

    public function getNodeList()
    {
        return ['0' => __('Node 0'), '1' => __('Node 1'), '2' => __('Node 2'), '3' => __('Node 3'), '4' => __('Node 4')];
    }

    public function getTriggerList()
    {
        return ['0' => __('Trigger 0'), '1' => __('Trigger 1')];
    }

    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1')];
    }

    public function getPlayList()
    {
        return ['0' => __('Play 0'), '1' => __('Play 1')];
    }


    public function getComeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['come']) ? $data['come'] : '');
        $list = $this->getComeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getAdtypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['adtype']) ? $data['adtype'] : '');
        $list = $this->getAdtypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getNodeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['node']) ? $data['node'] : '');
        $list = $this->getNodeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getTriggerTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['trigger']) ? $data['trigger'] : '');
        $list = $this->getTriggerList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getPlayTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['play']) ? $data['play'] : '');
        $list = $this->getPlayList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function user()
    {
        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function app()
    {
        return $this->belongsTo('App', 'app_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
